package com.fyl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fyl.entity.User;
import com.fyl.mapper.UserAddressMapper;
import com.fyl.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 馮永龍
 * @since 2020-11-27
 */
@Controller
@RequestMapping("//userAddress")
public class UserAddressController {

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Autowired
    private CartService cartService;

    @GetMapping("info")
    public ModelAndView info(HttpSession session) {
        User user = (User) session.getAttribute("user");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("userAddressList");
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_id", user.getId());
        modelAndView.addObject("userAddressList", this.userAddressMapper.selectList(wrapper));
        modelAndView.addObject("carts", this.cartService.findAllVO(user.getId()));
        return modelAndView;
    }
}

